using GGPhysics;
using UnityEngine;

public class GGPBody : MonoBehaviour
{
	public PhysicsBody body;

	public bool updateTransform = true;

	public Transform positionUpdateTransform;

	public Transform rotationUpdateTransform;

	public Renderer myRenderer;

	public bool skipUpdateForAFrame;

	private void OnDrawGizmos()
	{
	}

	public PhysicsBody GetBodyWithShape()
	{
		GGPShape component = GetComponent<GGPShape>();
		Shape shape = component.shape;
		if (shape == null)
		{
			Debug.LogError(string.Format("{0} has not got any shape", base.gameObject.name));
			return null;
		}
		body.shape = shape;
		return body;
	}

	public void LateUpdate()
	{
		if (skipUpdateForAFrame)
		{
			skipUpdateForAFrame = false;
		}
		else if (updateTransform)
		{
			SyncUnityTransform();
		}
	}

	public void SyncUnityTransform()
	{
		Vector3 position = base.transform.position;
		Transform transform = ((!(positionUpdateTransform != null)) ? base.transform : positionUpdateTransform);
		transform.position = body.currentTransform.position.OnGround(position.y);
		Transform transform2 = ((!(rotationUpdateTransform != null)) ? base.transform : rotationUpdateTransform);
		transform2.rotation = body.currentTransform.rotation;
	}

	public void SyncUnityTransformWithTime(float fixedDelta, float t)
	{
		PhysicsBody.Transform currentTransform = body.currentTransform;
		PhysicsBody.Transform b = body.TransformAfterDelta(fixedDelta);
		PhysicsBody.Transform transform = PhysicsBody.Transform.Lerp(currentTransform, b, t);
		Vector3 position = base.transform.position;
		Transform transform2 = ((!(positionUpdateTransform != null)) ? base.transform : positionUpdateTransform);
		transform2.position = transform.position.OnGround(position.y);
		Transform transform3 = ((!(rotationUpdateTransform != null)) ? base.transform : rotationUpdateTransform);
		transform3.rotation = transform.rotation;
	}
}
